package com.book.controller;

import com.book.service.BookService;
import com.book.utils.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api("图书馆藏Api")
@RestController
@RequestMapping("/book")
@CrossOrigin   //主要作用就是用来处理跨服务器访问数据的问题，该标签没有服务器之间是数据传递的
public class BookController {

    @Autowired
    private BookService bookService;

    //该方法它给客户端返回的数据格式是必须是json格式
    @ApiOperation("查询所有图书类别")
    @GetMapping("/list")
    public CommonResult list(int page , int size, String bname){
        Map<String , Object>  map= new HashMap<>();
        map.put("data",bookService.listPager(page,size,bname));
        map.put("total",bookService.count());
        return CommonResult.success(map);
    }
    @ApiOperation("根据ID删除图书信息")
    @DeleteMapping("/remove")
    public CommonResult remove(int cateid){
        System.out.println(cateid+"-------");
        return CommonResult.success(bookService.removeBook(cateid));

    }
}
